<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" session="false" %>
<%@ page import="com.atozsoft.commonutil.Constants"%>
<%@ page import="java.math.BigDecimal"%>
<%@ page import="com.eos.data.datacontext.UserObject" %>
<%@ page import="org.gocom.components.coframe.rights.dataset.CapUser"%>	

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
	<%@include file="/common.jsp"%>
	<%@include file="/common/common.jsp"%>
    <%@include file="/coframe/tools/skins/common.jsp"%>
	<title>项目立项管理一览</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
</head>
<body>
	<div class="search-condition">
	<a href="#" class="searchclose"></a>
		<div class="list">
        	<div id="queryprojectForm">
	        	<table style="width:100%;" class="table">
	            	<tr>
	              		<!-- <td class="tit" style="width:120px">
	              			立项文件编号：
	              		</td>
	              		<td>
	                		<input id="projectfilecode" class="nui-textbox " onEnter='onKeyEnter' name="projectfilecode" style="width:100%"/>
	              		</td> -->
	              		<td class="tit" style="width:120px">
	              			项目名称：
	              		</td>
	              		<td>
	                		<!-- <input id="projectname" class="nui-textbox " onEnter='onKeyEnter' name="projectname" style="width:100%"/> -->
	                		<input name="criteria._expr[0].projectname" class="nui-textbox" style="width:100%" onenter="onKeyEnter"/>
	                		<input class="nui-hidden" name="criteria._expr[0]._op" value="like"/>
                        	<input class="nui-hidden" name="criteria._expr[0]._likeRule" value="all"/>
	              		</td>
		              	<td class="tit" style="width:120px">
                   			项目来源：
	              		</td>
	              		<td>
	                		<input id="projectfrom" class="nui-dictcombobox nui-form-input" onenter="onKeyEnter" name="criteria._expr[1].projectfrom"  allowInput="false" dictTypeId="MIS_PROJECTFROM"/>
	                		<input class="nui-hidden" name="criteria._expr[1]._op" value="="/>
        				</td>
        				<td class="tit" style="width:120px">
                   			资金来源：
	              		</td>
	              		<td>
		          			<input id="moneyfrom" class="nui-dictcombobox nui-form-input" style="width:100%;" onenter="onKeyEnter" name="criteria._expr[2].moneyfrom"  allowInput="false" dictTypeId="MIS_MONEYFROM"/>
		          			<input class="nui-hidden" name="criteria._expr[2]._op" value="="/>
		        		</td>
	              		<td width="20px"></td>
	            	</tr>
          		    <tr>
          		    	<td class="tit" style="width:120px">
	              			项目类型：
	              		</td>
	              		<td>
	                		<input id="projecttype" class="nui-dictcombobox nui-form-input" style="width:100%;" onenter="onKeyEnter" name="criteria._expr[3].projecttype"  allowInput="false" dictTypeId="MIS_PROJECTTYPE"/>
	                		<input class="nui-hidden" name="criteria._expr[3]._op" value="="/>
		        		</td>
		        		<td class="tit" style="width:120px">
	              			立项年度：
	              		</td>
	              		<td>
	                		<!-- <input id="planyear" class="nui-textbox " onEnter='onKeyEnter' name="planyear" style="width:100%"/> -->
	                		<input id="planyear" class="nui-textbox nui-form-input" onEnter='onKeyEnter' name="criteria._expr[4].planyear"  style="width:100%"/>
	                		<input class="nui-hidden" name="criteria._expr[4]._op" value="="/>
	              		</td>
	              		<td class="tit" style="width:120px">
                   			数据状态：
	              		</td>
	              		<td>
		          			<input id="status" class="nui-dictcombobox nui-form-input" style="width:100%;" onenter="onKeyEnter" name="criteria._expr[5].status"  allowInput="false" dictTypeId="PROCESS_STATUS_TYPE"/>
		          			<input class="nui-hidden" name="criteria._expr[5]._op" value="="/>
		        		</td>
		        		<td width="20px"></td>
	            	</tr>
	            	<tr>
	              		<td class="tit">
		              		申报时间：
		              	</td>
		              	<td nowrap="nowrap" style="width:280px">
	                		<input id="startDate" class="nui-datepicker" onEnter='onKeyEnter' name="criteria._expr[6].declaringdate" style="width:48%;" onvalidation="onDateValidation" allowInput="false"/>
	                		<input class="nui-hidden" name="criteria._expr[6]._op" value=">="/>
							-
							<input id="endDate" class="nui-datepicker" onEnter='onKeyEnter' name="criteria._expr[7].declaringdate" style="width:48%;" onvalidation="onDateValidation" allowInput="false"/>
							<input class="nui-hidden" name="criteria._expr[7]._op" value="<="/>
		              	</td>
		              	<td class="tit" style="width:120px">
                   			申报单位：
	              		</td>
	              		<td>
	                		<input  id="declaringunitsid" class="nui-treeselect nui-form-input" name="criteria._expr[8].declaringunitsid" 
			       			url="com.shendong.mis.common.queryOrgOrganization.biz.ext" multiSelect="false"  valueFromSelect="false"
        					dataField="datas" textField="orgname" valueField="orgid" parentField="parentorgid"   allowInput="false"
       						showRadioButton="true" showFolderCheckBox="false" onbeforenodeselect="beforenodeselect" onEnter='onKeyEnter'
    						/>
    						<input class="nui-hidden" name="criteria._expr[8]._op" value="="/>
        				</td>
	              		
	              		<td width="20px"></td>
	            	</tr>
          		</table>
          		<table width="100%" border="0" cellspacing="0" cellpadding="0" class="search-btn-area">
					  <tr>
					     <td>
					      	<a class="nui-button" iconCls="icon-search" onclick="search">查询</a>&nbsp;&nbsp;
					      	<a class="nui-button" iconCls="icon-reload" onclick="clear">清空</a>
					     </td>
					  </tr>
		        </table>
        	</div>
      	</div>
    </div>
	<div style="padding:10px 0px 0px 0px;">
		<div class="nui-toolbar" style="border-bottom:0;">
        	<table style="width:100%;">
            	<tr>
		            <td style="width:100%;">
		                <a class="nui-button" iconCls="icon-add" onclick="add()">增加</a>
		            	<a class="nui-button" iconCls="icon-edit" onclick="edit()" id="edit_btn">编辑</a>
		            	<a class="nui-button" iconCls="icon-remove" onclick="remove()" id="delete_btn">删除</a>
		            </td>
	            </tr>
	        </table>
    	</div>
    </div>
    <div class="nui-fit">
  		<div id="projectDataGrid" class="nui-datagrid" style="width:100%;height:100%;"
  		 url="com.shendong.mis.projectEstablishment.queryProjectEstablishment.biz.ext" dataField="projects"
          	sizeList=[10,20,50,100] multiSelect="true" pageSize="20" allowAlternating="true" onselectionchanged="selectionChanged">
        	<div property="columns">
        		<div field="projectid" visible="false">ID</div>
          		<div type="checkcolumn" headerAlign="center" align="center">
          		</div>
          		<!-- <div field="projecttheme" allowSort="true" headerAlign="center">
        			立项文件编号
          		</div> -->
          		<div field="projectname" allowSort="true" headerAlign="center" renderer="urlRenderer"  width="150px">
        			项目名称
          		</div>
          		<div field="projectfrom" allowSort="true" headerAlign="center" renderer="onRender">
        			项目来源
          		</div>
          		<div field="moneyfrom" allowSort="true" headerAlign="center" renderer="onRender">
        			资金来源
          		</div>
          		<div field="projecttype" allowSort="true" headerAlign="center" renderer="onRender">
        			项目类型
          		</div>
          		<!-- <div field="declaringunitsid" visible="false">申报单位ID</div> -->
          		<div field="planyear" allowSort="true" headerAlign="center" >
        			立项年度
          		</div>
          		<div field="orgname" allowSort="true" headerAlign="center" >
        			申报单位
          		</div>
          		<div field="declaringdate" allowSort="true" headerAlign="center" >
        			申报日期
          		</div>
          		<div field="budgetamount" allowSort="true" headerAlign="center" >
        			经费预算（万元）
          		</div>
          		<div field="projectleader" visible="false">申报单位ID</div>
          		<div field="empname" allowSort="true" headerAlign="center" >
        			项目主管
          		</div>
          		<div field="status" allowSort="true" headerAlign="center" align="center" renderer="onRender">
            		数据状态
          		</div> 
          		<div field="creater" allowSort="true" headerAlign="center" visible="false" >
            		创建者
          		</div>
          		<div field="createdate" allowSort="true" headerAlign="center" align="center" dateFormat="yyyy-MM-dd" visible="false">
            		创建日期
          		</div> 
          		<div field="processinstid" visible="false">流程实例ID</div>
        	</div>
      	</div>
    </div>
    <script>
    	//数据渲染处理
    	function onRender(e){
    		if(e.field=="projectfrom"){
    			return nui.getDictText("MIS_PROJECTFROM",e.value);
    		}else if(e.field=="moneyfrom"){
    			return nui.getDictText("MIS_MONEYFROM",e.value);
    		}else if(e.field=="projecttype"){
    			return nui.getDictText("MIS_PROJECTTYPE",e.value);
    		}else if (this.field=="status"){
        	    if(e.row.status == "2"){
        	    	dictText = "<a href='#' onclick='showWFgraph("+e.row.processinstid+");'>已审核</a>";
        	    }else if(e.row.status == "1"){
        	    	dictText = "<a href='#' onclick='showWFgraph("+e.row.processinstid+");'>审核中</a>";
        	    }else{
	        	    if(e.row.processinstid != "" && e.row.processinstid != null){
	        	    	dictText = "<a href='#' onclick='showWFgraph("+e.row.processinstid+");'>保存</a>";
	        	    }else{
	        	    	dictText = "保存";
	        	    }
        	    }
        		return dictText;
    		}
    	}
    	
    	function userData1(){
	    	nui.open({
                url: "<%=request.getContextPath()%>/mis/orgUser/selectEmployee.jsp",
                title: "用户",
                width: 870,
                height: 550,
                onload: function () {
                	var iframe = this.getIFrameEl();
			        iframe.contentWindow.SetData({multiSelect:'false'});
                },
                ondestroy: function (action) {
              	 	if(action=="ok"){
              	 		var iframe = this.getIFrameEl();
                        var data = iframe.contentWindow.GetData();
                        data = nui.clone(data);    //必须克隆返回值
                        alert(nui.encode(data));
                        // 主管所领导赋值
                        nui.get("projectleader").setValue(data.empid);
                        nui.get("projectleader").setText(data.username);     	 	
                    }
                }
            });
	    }
    	
      	function showWFgraph(processInstId){
	    	var zoomvalue = 1;
	    	nui.open({
	            url: "<%=request.getContextPath()%>/wf/processOperate/process_Approve.jsp?processInstId=" + processInstId + "&zoomvalue=" + zoomvalue,
		        title: "查看审批进度",
				width: 700, 
		        height: 635,
		        onload: function() {
		        },
		        ondestroy: function (action) {
					
	             }
		    });
      	}
      	
      	// 清空查询条件
	   function clear(){
			var form = new nui.Form("#queryprojectForm");
			form.reset();
		}
    </script>
	<script type="text/javascript">
    	nui.parse();
    	
    	//跳转方式修改为弹出TAB
    	var postUrl="<%=request.getContextPath()%>/mis/common/postUrl.jsp?";

    	var grid = nui.get("projectDataGrid");
    	// 初始数据
    	grid.load();
    	grid.sortBy("createdate", "desc");s
    
  		// 查询按钮
  		function search(){
  			var form = new nui.Form("#queryprojectForm");
		    var data = form.getData();//获取表单JS对象数据 
		    grid.load(data);//datagrid加载数据
  		}
  		
  		// 回车执行查询
  		function onKeyEnter(e) {
    		search();
  		}
  		
  		// 增加按钮
  		function add() {
  			// 增加按钮
        	var actionFlg = "add";
        	var projectId = "";
        	var workitemid = "";
        	var processInstId = "";
        	addDetailTab(actionFlg,projectId,processInstId,workitemid, "项目申报新增");  
        }
        
        // 修改按钮
        function edit() {
            var row = grid.getSelected();
            if (row) {
	  			onUrl("update",row.projectid,row.processinstid,row.workitemid,"项目申报修改");
            } else {
                nui.alert("请选中一条记录！","提示");
            }
        }
        // 跳转页面
     	function onUrl(actionFlg,projectId,processInstId,workitemid,title){ 
			// 跳转页面并传参（post）      
			addDetailTab(actionFlg,projectId,processInstId,workitemid,title);		 
		}
		
		/*
		* 重新打开一个tab页显示详细页面
		* actionFlg: 操作类型
		* guaranteeletterId: ID
		*/
      	function addDetailTab(actionFlg,projectId,processInstId,workitemid,title){
      		var url ="<%=request.getContextPath()%>/mis/projectEstablishment/projectEstablishment_detail.jsp"; 
      		
			var params=nui.encode({actionFlg:actionFlg,projectId:projectId,processInstId:processInstId,workitemid:workitemid});
			var tabName = "project_menu";
			if(projectId != null && projectId != ""){
				tabName = tabName + "_" +projectId;
			}
			//alert(projectId);
			window.parent.addtabs(postUrl+"url="+url+"&params="+encodeURIComponent(params),title, tabName); 
      	} 
        
        // 数据链接跳转相关
      	function urlRenderer(e) 
      	{	
      		return "<a class='viewbutton' href='javascript:void()' onclick=onUrl('view','"+e.row.projectid+"','"+e.row.processinstid+"','','项目申报明细')>"+e.row.projectname+"</a>";
     	}
     	

        
        // 删除按钮
        function remove() {
            var rows = grid.getSelecteds();
            if (rows.length > 0) {
            	nui.confirm("确认删除勾选项目申报信息？","删除确认",function(action){
	            	if(action!="ok") return;
	  				var json = nui.encode({projects:rows});
	                $.ajax({
	                    url: "com.shendong.mis.projectEstablishment.deleteProjectEstablishment.biz.ext",
		                type: 'POST',
		                data: json,
		                cache: false,
		                contentType:'text/json',
	                    success: function (text) {
	                    	var returnJson = nui.decode(text);
							if(returnJson.resultStr == 'SUCCESS'){
								nui.alert("项目申报删除成功！", "提示");
	                        }
	                        else{
	                        	nui.alert("项目申报删除失败！", "提示");
                        	}
                        	grid.reload();
	                    },
	                    error: function () {
	                    	nui.alert("项目申报删除异常！", "提示");
	                    }
	                });
                }); 
            } else {
                nui.alert("请选中一条记录！","提示");
            }
        }
  		
  		// 列表选中行时，根据权限设置编辑删除按钮
        function selectionChanged(){
			// 默认可编辑
			nui.get("edit_btn").enable();
			nui.get("delete_btn").enable();
			
			var row = grid.getSelected();
			// 列表选中多条记录时，编辑按钮不可用
			var rows = grid.getSelecteds();
			if(rows.length>1){
				nui.get("edit_btn").disable();
			}else{
				nui.get("edit_btn").enable();
			}
			// 判断是否选择
			if(row){
				if(row.status == "0")
				{ 
					// 存在则不能编辑
					nui.get("edit_btn").enable();
					nui.get("delete_btn").enable();
				}else
				{
				   nui.get("edit_btn").disable();
				   nui.get("delete_btn").disable();
				}
			}
		}
		
		//各种监听事件
        $(document).ready(
			function(){
			   //收起查询窗口
			   $(".search-condition .searchclose").click(function(){
			  		$(".search-condition .list").toggle();
					setTimeout("nui.layout()", 10 );
			   });
			}
		);
		
		//写完treeSelect必须加这个函数，要不选不到
    	function beforenodeselect(e) {
            //禁止选中父节点
            if (e.isLeaf == false) e.cancel = true;
        }
    </script>
</body>
</html>